package org.paradigmshift.timelapse.ui

import javax.swing.table.AbstractTableModel
import org.paradigmshift.timelapse.domain.Issue
import org.paradigmshift.timelapse.domain.User
import javax.swing.event.TableModelEvent

object IssueTableModel {
  val columnNames = Array( "Key", "Priority", "Description" )
}

class IssueTableModel extends AbstractTableModel {
  
  private var issues:List[Issue] = Nil
  
  def setIssues( issues:List[Issue] ) {
    this.issues = issues
    this.fireTableChanged( new TableModelEvent( this ) )
  }
  
  def getRowCount(): Int = issues.size
  def getColumnCount(): Int = IssueTableModel.columnNames.length
  def getValueAt(rowIndex: Int, columnIndex: Int): Object = {
    val issue = issues( rowIndex )
    return columnIndex match {
      case 0 => issue.key.getOrElse( "" )
      case 1 => issue.priority
      case 2 => issue.description
      case _ => throw new IndexOutOfBoundsException()
    }
  }
  override def getColumnName( col: Int ): String = IssueTableModel.columnNames( col )
  override def isCellEditable( row: Int, col: Int ): Boolean = false
}